package cn.itsource._02workqueue;

import cn.itsource.utils.RabbitMQUtil;
import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DefaultConsumer;
import com.rabbitmq.client.Envelope;
import java.io.IOException;

/**
 * @Author: CTL
 * @Description: 消费者2
 * @DateTime: 2023年06月13日 18:22
 */

public class Consumer2 {
    public static void main(String[] args) throws Exception {
        // 1.获取连接
        Channel channel = RabbitMQUtil.getchannel();
        channel.basicConsume(Producer.AIMPLE_QUEUE_NAME,false,new DefaultConsumer(channel){
            @Override
            public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
                String message = new String(body, "UTF-8");
                System.out.println(" 消费者2 '" + message + "'");
                System.out.println(envelope.getDeliveryTag());
                channel.basicAck(envelope.getDeliveryTag(),false);
            }
        });
    }
}
